Last updated: 2025-10-17

Checks: 6 1

Knit directory: 13384_GBMHGG_SPP1_Xenium/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20251010) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Using absolute paths to the files within your workflowr project makes it difficult for you and others to run your code on a different machine. Change the absolute path(s) below to the suggested relative path(s) to make your code more reproducible.

absolute relative
/home/hnatri/13384_GBMHGG_SPP1_Xenium/ .
/home/hnatri/13384_GBMHGG_SPP1_Xenium/code/olors_themes.R code/olors_themes.R
/home/hnatri/13384_GBMHGG_SPP1_Xenium/code/plot_functions.R code/plot_functions.R
/home/hnatri/13384_GBMHGG_SPP1_Xenium/main_cluster_markers.tsv main_cluster_markers.tsv
/home/hnatri/13384_GBMHGG_SPP1_Xenium/main_top_markers.tsv main_top_markers.tsv

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 943d665. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


working directory clean

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/annotation.Rmd) and HTML (docs/annotation.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd b986e82 heinin 2025-10-16 Spatial plots of marker expression

Import packages

suppressPackageStartupMessages({
  library(workflowr)
  library(arrow)
  library(Seurat)
  library(SeuratObject)
  library(SeuratDisk)
  library(tidyverse)
  library(tibble)
  library(ggplot2)
  library(ggpubr)
  library(ggrepel)
  library(googlesheets4)
  library(workflowr)})

Environment variables and helper functions

setwd("/home/hnatri/13384_GBMHGG_SPP1_Xenium/")
set.seed(9999)
options(scipen = 99999)
options(ggrepel.max.overlaps = Inf)

#source("/home/hnatri/13384_GBMHGG_SPP1_Xenium/code/olors_themes.R")
source("/home/hnatri/13384_GBMHGG_SPP1_Xenium/code/plot_functions.R")

Import data

# Copied to isilon /tgen_labs/banovich/PIPAC/Seurat
seurat_data <- readRDS("/tgen_labs/banovich/BCTCSF/13384_GBMHGG_Xenium/Seurat/spatial_clustered_NN30_PC50_Seurat.rds")

# Removing UnassignedCodewords from the expression data
seurat_data <- subset(seurat_data, features = rownames(seurat_data)[-grep("UnassignedCodeword", rownames(seurat_data))])

seurat_data <- NormalizeData(seurat_data)
seurat_data <- ScaleData(seurat_data)

# saveRDS(seurat_data, "/tgen_labs/banovich/BCTCSF/13384_GBMHGG_Xenium/Seurat/cell_clustered_NN30_PC50_Seurat.rds")

DimPlot(seurat_data,
        group.by = "leiden_1.0",
        #cols = main_cluster_col,
        reduction = "umap",
        raster = T,
        label = T) +
  coord_fixed(ratio = 1) +
  theme_classic() +
  NoLegend()

DimPlot(seurat_data,
        reduction = "sp",
        group.by = "leiden_1.0",
        raster = T,
        label = F) +
    coord_fixed(ratio = 1) +
    theme_minimal() +
    NoLegend() +
    ggtitle("TMA1_0069754")

Feature expression

grep("OLIG", rownames(seurat_data), value = T)
[1] "OLIG1" "OLIG2"
plot_features <- c("PTPRC",
                   "CD3D", "CD3E", "CD4", "CD8A", # T cells
                   "STAT4", "STAT3", "GZMB",
                   "SELL", "CD19", # B cells
                   "CD68", "CD44", "MARCO", "APOE", "C1QB", "SPP1",
                   "MS4A1", # Lineage markers
                   "FN1", "COL1A1", # Fibroblasts
                   "TP53", "KIT", # Tumor
                   "EPCAM",
                   "OLIG1", "OLIG2")

DotPlot(seurat_data,
        group.by = "leiden_1.0",
        features = plot_features,
        cols = c("gray89", "tomato3")) +
  RotatedAxis()

FeaturePlot(seurat_data,
            slot = "data",
            features = plot_features,
            order = T,
            ncol = 5,
            reduction = "umap",
            raster = T,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  theme_bw() &
  NoLegend()

FeaturePlot(seurat_data,
            slot = "data",
            #split.by = "Sample",
            features = plot_features,
            order = T,
            reduction = "sp",
            raster = T,
            ncol = 4,
            cols = c("gray89", "tomato3")) &
  coord_fixed(ratio = 1) &
  theme_bw() &
  NoLegend()

DenoIST

DefaultAssay(seurat_data) <- "denoist_RNA"
DotPlot(seurat_data,
        group.by = "leiden_1.0",
        features = plot_features,
        cols = c("azure", "tomato3")) +
  RotatedAxis()

Top cluster markers

Idents(seurat_data) <- seurat_data$"leiden_1.0"
cluster_markers <- FindAllMarkers(seurat_data,
                                  return.thresh = 0.01,
                                  logfc.threshold = 0.5,
                                  min.pct = 0.20,
                                  verbose = T)

table(cluster_markers$cluster)

 1 19  4 15 13  2 20  9  0  5 14 18  8 10 11  3 16  6  7 17 12 
45 28 54 56 36 41 87 20 87 17 44 25 40 31 57 58 27 43 62 41 47 
#hist(cluster_markers$avg_log2FC, main = "", xlab = "avg_log2FC", breaks = 100)
#hist(cluster_markers$p_val, main = "", xlab = "p_val", breaks = 100)
#hist(cluster_markers$p_val_adj, main = "", xlab = "p_val_adj", breaks = 100)

top_cluster_markers <- cluster_markers %>%
  arrange(dplyr::desc(avg_log2FC)) %>%
  group_by(cluster) %>%
  dplyr::slice(1:10)
create_dotplot_heatmap(seurat_object = seurat_data,
                       plot_features = unique(top_cluster_markers$gene),
                       group_var = "leiden_1.0",
                       group_colors = main_cluster_col,
                       column_title = "",
                       row_km = 5,
                       col_km = 5,
                       row.order = NULL,
                       col.order = NULL)

Saving top markers and annotations

output_cluster_markers <- cluster_markers %>%
  arrange(dplyr::desc(avg_log2FC)) %>%
  group_by(cluster) %>%
  dplyr::slice(1:30)

output_cluster_markers <- merge(top_cluster_markers, markers, by.x = "gene", by.y = "Gene")

write.table(output_cluster_markers, "/home/hnatri/13384_GBMHGG_SPP1_Xenium/main_cluster_markers.tsv",
            quote = F, row.names = F, sep = "\t")

# Saving DenoIST top markers by original annotation
Idents(seurat_data) <- seurat_data$Annotation
cluster_markers <- FindAllMarkers(seurat_data,
                                  return.thresh = 0.01,
                                  logfc.threshold = 0.5,
                                  min.pct = 0.20,
                                  verbose = T)

output_cluster_markers <- cluster_markers %>%
  arrange(dplyr::desc(avg_log2FC)) %>%
  group_by(cluster) %>%
  dplyr::slice(1:30)

output_cluster_markers <- merge(top_cluster_markers, markers, by.x = "gene", by.y = "Gene")

write.table(output_cluster_markers, "/home/hnatri/13384_GBMHGG_SPP1_Xenium/main_top_markers.tsv",
            quote = F, row.names = F, sep = "\t")

Subsetting immune and non-immune cells for subclustering

seurat_data$Lineage <- ifelse(seurat_data$leiden_0.5 %in% c(5, 6),
                              "Immune", "TumorStroma")

immune_subset <- subset(seurat_data, subset = Lineage == "Immune")
nonimmune_subset <- subset(seurat_data, subset = Lineage == "TumorStroma")

saveRDS(immune_subset, "/scratch/hnatri/13384_GBMHGG_SPP1_Xenium/cell_immune_subset.rds")
saveRDS(nonimmune_subset, "/scratch/hnatri/13384_GBMHGG_SPP1_Xenium/cell_nonimmune_subset.rds")

# To build on command line, run Rscript -e "rmarkdown::render('annotation_cell.Rmd')"
# Then "mv *.html /home/hnatri/13384_GBMHGG_SPP1_Xenium/docs/"

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ComplexHeatmap_2.18.0 viridis_0.6.3         viridisLite_0.4.2    
 [4] RColorBrewer_1.1-3    googlesheets4_1.1.0   ggrepel_0.9.3        
 [7] ggpubr_0.6.0          lubridate_1.9.2       forcats_1.0.0        
[10] stringr_1.5.0         dplyr_1.1.2           purrr_1.0.1          
[13] readr_2.1.4           tidyr_1.3.0           tibble_3.2.1         
[16] ggplot2_3.4.2         tidyverse_2.0.0       SeuratDisk_0.0.0.9021
[19] Seurat_5.0.1          SeuratObject_5.0.1    sp_1.6-1             
[22] arrow_21.0.0.1        workflowr_1.7.1      

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.20       splines_4.3.0          later_1.3.1           
  [4] cellranger_1.1.0       polyclip_1.10-4        fastDummies_1.7.3     
  [7] lifecycle_1.0.3        rstatix_0.7.2          doParallel_1.0.17     
 [10] rprojroot_2.0.3        globals_0.16.2         processx_3.8.1        
 [13] lattice_0.21-8         hdf5r_1.3.8            MASS_7.3-60           
 [16] backports_1.4.1        magrittr_2.0.3         limma_3.58.1          
 [19] plotly_4.10.2          sass_0.4.6             rmarkdown_2.22        
 [22] jquerylib_0.1.4        yaml_2.3.7             httpuv_1.6.11         
 [25] sctransform_0.4.1      spam_2.9-1             spatstat.sparse_3.0-1 
 [28] reticulate_1.29        cowplot_1.1.1          pbapply_1.7-0         
 [31] abind_1.4-5            Rtsne_0.16             presto_1.0.0          
 [34] BiocGenerics_0.48.1    git2r_0.32.0           circlize_0.4.15       
 [37] S4Vectors_0.40.2       IRanges_2.36.0         irlba_2.3.5.1         
 [40] listenv_0.9.0          spatstat.utils_3.0-3   goftest_1.2-3         
 [43] RSpectra_0.16-1        spatstat.random_3.1-5  fitdistrplus_1.1-11   
 [46] parallelly_1.36.0      leiden_0.4.3           codetools_0.2-19      
 [49] shape_1.4.6            tidyselect_1.2.0       farver_2.1.1          
 [52] stats4_4.3.0           matrixStats_1.0.0      spatstat.explore_3.2-1
 [55] googledrive_2.1.0      jsonlite_1.8.5         GetoptLong_1.0.5      
 [58] ellipsis_0.3.2         progressr_0.13.0       ggridges_0.5.4        
 [61] survival_3.5-5         iterators_1.0.14       foreach_1.5.2         
 [64] tools_4.3.0            ica_1.0-3              Rcpp_1.0.10           
 [67] glue_1.6.2             gridExtra_2.3          xfun_0.39             
 [70] withr_2.5.0            fastmap_1.1.1          fansi_1.0.4           
 [73] callr_3.7.3            digest_0.6.31          timechange_0.2.0      
 [76] R6_2.5.1               mime_0.12              colorspace_2.1-0      
 [79] scattermore_1.2        tensor_1.5             spatstat.data_3.0-1   
 [82] utf8_1.2.3             generics_0.1.3         data.table_1.14.8     
 [85] httr_1.4.6             htmlwidgets_1.6.2      whisker_0.4.1         
 [88] uwot_0.1.14            pkgconfig_2.0.3        gtable_0.3.3          
 [91] lmtest_0.9-40          htmltools_0.5.5        carData_3.0-5         
 [94] dotCall64_1.0-2        clue_0.3-64            scales_1.2.1          
 [97] png_0.1-8              knitr_1.43             rstudioapi_0.14       
[100] rjson_0.2.21           tzdb_0.4.0             reshape2_1.4.4        
[103] nlme_3.1-162           GlobalOptions_0.1.2    cachem_1.0.8          
[106] zoo_1.8-12             KernSmooth_2.23-21     parallel_4.3.0        
[109] miniUI_0.1.1.1         pillar_1.9.0           vctrs_0.6.2           
[112] RANN_2.6.1             promises_1.2.0.1       car_3.1-2             
[115] xtable_1.8-4           cluster_2.1.4          evaluate_0.21         
[118] cli_3.6.1              compiler_4.3.0         rlang_1.1.1           
[121] crayon_1.5.2           future.apply_1.11.0    ggsignif_0.6.4        
[124] labeling_0.4.2         ps_1.7.5               getPass_0.2-4         
[127] plyr_1.8.8             fs_1.6.2               stringi_1.7.12        
[130] deldir_1.0-9           assertthat_0.2.1       munsell_0.5.0         
[133] lazyeval_0.2.2         spatstat.geom_3.2-1    Matrix_1.6-5          
[136] RcppHNSW_0.5.0         hms_1.1.3              patchwork_1.1.2       
[139] bit64_4.0.5            future_1.32.0          statmod_1.5.0         
[142] shiny_1.7.4            highr_0.10             ROCR_1.0-11           
[145] gargle_1.4.0           igraph_1.4.3           broom_1.0.4           
[148] bslib_0.4.2            bit_4.0.5